package com.ss.user.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ss.common.MapResult;
import com.ss.user.dao.UserDao;
import com.ss.user.pojo.UserInfo;
import com.ss.user.service.UserService;
/**
 * 用户管理
 * @author Administrator
 *
 */
@Service("userService")
public class UserServiceImpl implements UserService {
	
	@Autowired
	private UserDao dao;
	public void addUser(UserInfo info) throws Exception {
		// TODO Auto-generated method stub
		dao.addUser(info);
	}
	@Override
	public List<UserInfo> queryUser(UserInfo info) throws Exception {
		// TODO Auto-generated method stub
		return dao.queryUser(info);
	}
	@Override
	public MapResult login(UserInfo info) throws Exception {
		// TODO Auto-generated method stub
		UserInfo us=dao.getUserByName(info.getUser_name());
		MapResult mr=new MapResult();
		if(us!=null){
			if(us.getStatus().equals("0")){
				mr.setMsg("无效用户");
			}else if(us.getUser_password().equals(info.getUser_password())){
				dao.markLoginTime(us.getId());
				mr.setIfSuccess(true);
				mr.setObj(us);
			}else{
				mr.setMsg("密码错误");
			}
		}else{
			mr.setMsg("用户不存在");
		}
		return mr;
	}
	@Override
	public UserInfo getUserById(String id) throws Exception {
		// TODO Auto-generated method stub
		return dao.getUserById(id);
	}
	@Override
	public boolean updateUser(UserInfo info) throws Exception {
		// TODO Auto-generated method stub
		int ret= dao.updateUser(info);
		return ret==0?false:true;
	}
	@Override
	public boolean auditUser(Map<String, Object> map) throws Exception {
		// TODO Auto-generated method stub
		int r= dao.auditUser(map);
		return r>0?true:false;
	}
	
}
